package com.glela.order.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import com.glela.order.model.AfterSales;

/**
 * 
 * @author MaoZeYao
 *
 */
public interface AfterSalesMapper {

	/**
	 * 查询子订单单号
	 * 
	 * @param orderInfoId
	 * @return
	 */
	public String selectOrderInfoSnByOrderInfoId(Long orderInfoId);

	/**
	 * 提交售后申请
	 * @param afterSales
	 * @return
	 */
	public int insertIntoAfterSales(AfterSales afterSales);

	/**
	 * 根据售后单号查询售后信息
	 * 
	 * @param customerServiceNumber
	 * @return
	 */
	public AfterSales selectAfterSalesByCustomerServiceNumber(String customerServiceNumber);

	/**
	 * 提交售后申诉
	 * 
	 * @param type
	 * @param supplementaryReason
	 * @param id
	 */
	public int updateAfterSalesTypeToComplaint(@Param("type") int type,
			@Param("supplementaryReason") String supplementaryReason, @Param("id") Long id,
			@Param("userRefundReason") String userRefundReason, @Param("imgProof1") String imgProof1,
			@Param("imgProof2") String imgProof2, @Param("imgProof3") String imgProof3,
			@Param("isRefund") int isRefund);

	/**
	 * 查询所有的售后订单
	 * 
	 * @return
	 */
	public List<AfterSales> selectAfterSalesByUserId(@Param("userId") Long userId, @Param("page") int page,
			@Param("pageSize") int pageSize);

	/**
	 * 查询售后中的订单
	 * 
	 * @param userId
	 * @return
	 */
	public List<AfterSales> selectAfterSalesInApplicationByUserId(Long userId);

	/**
	 * 查询申诉中的订单
	 * 
	 * @param userId
	 * @return
	 */
	/*
	 * public List<AfterSales> selectAfterSalesInComplaintByUserId(Long userId);
	 */

	/**
	 * 查询售后订单详情
	 * 
	 * @param afterSalesId
	 * @return
	 */
	public AfterSales selectAfterSalesByPrimyKey(Long afterSalesId);

	/**
	 * 根据图片位置修改图片
	 * 
	 * @param index
	 * @param url
	 * @return
	 */
	public int updateImagePoolsByIndex(@Param("index") int index, @Param("url") String url,
			@Param("afterSalesId") Long afterSalesId);

	/**
	 * 填写快递公司信息
	 * 
	 * @param afterSalesId
	 * @param courierCompany
	 * @param courierNumber
	 * @return
	 */
	public int updateCourierInformation(@Param("afterSalesId") Long afterSalesId,
			@Param("courierCompany") String courierCompany, @Param("courierCompanyEn") String courierCompanyEn,
			@Param("courierNumber") String courierNumber);

	/**
	 * 根据订单详情的ID查询售后信息
	 * 
	 * @param orderDetailId
	 * @return
	 */
	public AfterSales selectAfterSalesByOrderDetailId(Long orderDetailId);

	/**
	 * 某个用户的售后中的订单数量
	 * 
	 * @author 卫耀华
	 * @param userId
	 * @return
	 */
	public int selectAfterSalesOrderNum1(@Param("userId") Long userId);

	/**
	 * 某个用户的售后申诉中的订单数量
	 * 
	 * @author 卫耀华
	 * @param userId
	 * @return
	 */
	public int selectAfterSalesOrderNum2(@Param("userId") Long userId);

	public int updateAfterSalesStatusById(@Param("id") Long id, @Param("status") int status,
			@Param("refundId") String refundId);

//	public int updateAfterSalesStatusRefusedById(@Param("id") Long id, @Param("status") int status);

	public int updateAfterSalesStoreRefusedReason(@Param("id") Long id, @Param("status") int status,
			@Param("storeRefuseReason") String storeRefuseReason);

	public int updateAfterSalesStoreRefusedReason1(@Param("id") Long id, @Param("status") int status,
			@Param("storeRefuseReason1") String storeRefuseReason1);

	/**
	 * 查询总价格
	 * 
	 * @return
	 */
	public long selectFatherOrdersOfTotalPrice(long orderObjectId);

	/**
	 * 成功退款的金额
	 * 
	 * @param orderObjectId
	 * @return
	 */
	public long selectRefundSuccessMoney(long orderObjectId);

	/**
	 * 根据校妆返回的参数查询售后购单
	 * @param returnSn
	 * @return
	 */
	public AfterSales selectAfterSalesByReturnSn(String returnSn);

	/**
	 * 保存来自校妆的售后信息
	 * @param afterSn
	 * @param returnSn
	 * @return
	 */
	public int updateAfterSalesReturnOrderId(@Param("afterSn") String afterSn, @Param("returnSn")String returnSn);

	public int updateAfterSalesGoodsInformation(@Param("id") long id, @Param("defectiveGoods") String defectiveGoods);

	public int updateAfterSalesReturnOrderIdByOrderInfoSn(@Param("orderInfoSn")String orderInfoSn, @Param("returnSn")String returnSn);
	/**
	 * 保存运费退账的信息
	 * @param afterSn
	 * @param returnSn
	 * @author gaoweiqi 
	 * @return
	 */
	public int updateAfterSalesByID(@Param("id") long id, @Param("refund_freight_json") String refund_freight_json,
			@Param("refund_freight_id") String refund_freight_id,@Param("refund_freight") Integer freight);

	public int updateSendBackById(@Param("id") long id, @Param("sendBack") int sendBack);

	public List<AfterSales> selectTempSQL();

	public List<Map<Object, Object>> selectstudentwner();
	/**
	 * 保存余额妆币 运费退账的信息
	 * @param afterSn
	 * @param returnSn
	 * @author gaoweiqi 
	 * @return
	 */
	public int updateAfterSalesFreightByID(@Param("id") Long id, @Param("coinfreight") Integer coinfreight,
			@Param("balancefreight") Integer balancefreight);

	/**
	 * 根据售后单修改售后类型
	 * @param afterSn
	 * @param is_refund
	 * @author gaoweiqi 
	 * @return
	 */
	public int updateAfterSalesRefundTypeByCustomerServiceNumber(
			@Param("afterSn")String afterSn,@Param("is_refund") int is_refund);

	/**
	 * 根据售后单更新时间查找售后单集合（按照订单ID排序 ）
	 * @param beginTime
	 * @param endTime
	 * @author gaoweiqi 
	 * @return List<AfterSales>
	 */
	public List<AfterSales> selectAfterSalesByUpdateTime(@Param("beginTime")String beginTime,
			@Param("endTime")String endTime);

    public int selectAfterSalesOrderNum1Batch(@Param("userIds") List<Long> userIds);

	public int selectAfterSalesOrderNum2Batch(@Param("userIds") List<Long> userIds);
}
